package com.google.code.coma.domain;

import com.google.code.coma.space.Id;
import com.google.code.coma.space.SpaceEntity;

import java.io.Serializable;

/**
 * @author Dominik Strasser, dominikstr@gmail.com
 */
@SpaceEntity("part_")
public class Part implements Serializable {
	@Id(generator = Id.GenerationType.AUTO_GENERATED)
	private String id;

	private boolean broken;

	private String creator;

	private Type type;

	private String appellation;	

	public Part(Type type, String creator, boolean broken) {
		if (type == null)
			throw new IllegalArgumentException("Type must not be null");
		this.type = type;
		this.creator = creator;
		this.broken = broken;
	}

	public Part(Type type, String creator, boolean broken,String appellation) {
		this(type,creator,broken);
		this.appellation= appellation;
	}	

	public String getId() {
		return id;
	}

	public boolean isBroken() {
		return broken;
	}


	public String getCreator() {
		return creator;
	}

	public Type getType() {
		return type;
	}

	public String getAppellation() {
		return appellation;
	}

	@Override
	public String toString() {
		return "Part{" +
				"id='" + id + '\'' +
				", type=" + type +
				'}';
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		Part part = (Part) o;

		if (id != null ? !id.equals(part.id) : part.id != null) return false;

		return true;
	}

	@Override
	public int hashCode() {
		return id != null ? id.hashCode() : 0;
	}
}
